package com.specialtreasure.freightdepot.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.core.activity.BaseNewActivity;
import com.app.core.util.CommonUtil;
import com.app.core.util.DateUtils;
import com.app.core.view.ListViewForScrollView;
import com.bumptech.glide.Glide;
import com.specialtreasure.freightdepot.R;
import com.specialtreasure.freightdepot.adapter.CarDetaileListAdapter;
import com.specialtreasure.freightdepot.model.ItemBean;
import com.specialtreasure.freightdepot.model.ItemDetailList;
import com.specialtreasure.freightdepot.model.ZUserResponse;

import java.util.List;

/**
 * Created by Administrator on 2017/9/1 0001.
 * 货源详情页
 */

public class InformationDetailsActivity extends BaseNewActivity implements View.OnClickListener {

    public static final String TAG = "InformationDetailsActivity";
    ItemBean itemBean;
    CarDetaileListAdapter carDetaileListAdapter;

    private ImageView iv_back;
    private TextView tv_title;
    private TextView tv_chufadi;
    private TextView tv_mudidi;
    private TextView tv_licheng;
    private TextView tv_unit;
    private TextView tv_goods_type;
    private TextView tv_delivery_method;
    private TextView tv_goods_cost;
    private TextView tv_loadingAddress;
    private TextView tv_unloadingAddress;
    private TextView tv_collectionMoney;
    private ListViewForScrollView lv_goods;
    private TextView tv_name;
    private TextView tv_tel;
    private TextView tv_public_time;
    private ImageView iv_photo1;
    private ImageView iv_photo2;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_information_detail);
        initView();
        setData();
    }

    private void setData() {
        show(iv_back);
        tv_title.setText("详情");
        itemBean= (ItemBean) getIntent().getSerializableExtra("itemBean");
        carDetaileListAdapter=new CarDetaileListAdapter(this);

        if (itemBean!=null){
            tv_chufadi.setText(itemBean.getStartProvinceAddress()+itemBean.getStartCityAddress()+itemBean.getStartCountyAddress());
            tv_mudidi.setText(itemBean.getDestProvinceAddress()+itemBean.getDestCityAddress()+itemBean.getStartCountyAddress());

            if (itemBean.getMileage()==null){
                tv_licheng.setText("");
            }else {
                tv_licheng.setText(itemBean.getMileage()+"公里");
            }

            tv_unit.setText(itemBean.getGoodsNum());
            tv_goods_type.setText(itemBean.getGoodsType());
            tv_delivery_method.setText(itemBean.getSendStyle());

            if (itemBean.getGoodsTrans()==null){
                tv_goods_cost.setText("");
            }else {
                tv_goods_cost.setText(itemBean.getGoodsTrans()+"元");
            }


            tv_loadingAddress.setText(itemBean.getLoadingAddress());
            tv_unloadingAddress.setText(itemBean.getUnloadingAddress());


            if (itemBean.getCollectionMoney()==null){
                tv_collectionMoney.setText("");
            }else {
                tv_collectionMoney.setText(itemBean.getCollectionMoney()+"元");
            }


            tv_public_time.setText(DateUtils.timeMinute(itemBean.getPushTime()));

            //加载图片
            Glide.with(this).load(itemBean.getPhoto1()).into(iv_photo1);
            Glide.with(this).load(itemBean.getPhoto2()).into(iv_photo2);

            //用户信息
            ZUserResponse zUserResponse = itemBean.getzUserResponse();
            if (zUserResponse!=null){
                tv_name.setText(zUserResponse.getRealName());
                tv_tel.setText(zUserResponse.getPhoneNumber());

            }

            //随车清单
            List<ItemDetailList> itemDetailList= itemBean.getItemDetailList();
            carDetaileListAdapter.addAll(itemDetailList);
            lv_goods.setAdapter(carDetaileListAdapter);


        }

    }


    private void initView() {
        iv_back = (ImageView) findViewById(R.id.iv_back);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_chufadi = (TextView) findViewById(R.id.tv_chufadi);
        tv_mudidi = (TextView) findViewById(R.id.tv_mudidi);
        tv_licheng = (TextView) findViewById(R.id.tv_licheng);
        tv_unit = (TextView) findViewById(R.id.tv_unit);
        tv_goods_type = (TextView) findViewById(R.id.tv_goods_type);
        tv_delivery_method = (TextView) findViewById(R.id.tv_delivery_method);
        tv_goods_cost = (TextView) findViewById(R.id.tv_goods_cost);
        tv_loadingAddress = (TextView) findViewById(R.id.tv_loadingAddress);
        tv_unloadingAddress = (TextView) findViewById(R.id.tv_unloadingAddress);
        tv_collectionMoney = (TextView) findViewById(R.id.tv_collectionMoney);
        lv_goods = (ListViewForScrollView) findViewById(R.id.lv_goods);
        tv_name = (TextView) findViewById(R.id.tv_name);
        tv_tel = (TextView) findViewById(R.id.tv_tel);
        tv_public_time = (TextView) findViewById(R.id.tv_public_time);
        iv_photo1 = (ImageView) findViewById(R.id.iv_photo1);
        iv_photo2 = (ImageView) findViewById(R.id.iv_photo2);

        iv_back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }



    @Override
    public String getActiviyName() {
        return TAG;
    }



}
